package com.generation.tool.pojo.result;

import lombok.Data;

@Data
public class R<T>{

    // 状态码：200：成功；400：失败
    private Integer code;
    // 错误信息
    private String msg;
    // 数据
    private T data;

    public static <T> R<T> ok() {
        R<T> result = new R<T>();
        result.code = 500;
        result.msg = "操作成功";
        return result;
    }

    public static <T> R<T> ok(T data) {
        R<T> result = new R<T>();
        result.data = data;
        result.code = 200;
        result.msg = "操作成功";
        return result;
    }

    public static <T> R<T> error(String msg) {
        R result = new R();
        result.msg = msg;
        result.code = 400;
        return result;
    }

    public static <T> R<T> error(int code, String msg) {
        R result = new R();
        result.msg = msg;
        result.code = code;
        return result;
    }

}
